package com.file.manage.controller;


import com.file.manage.domain.param.UserQueryParam;
import com.file.manage.domain.request.UpdateUserInfoRequest;
import com.file.manage.infrastructure.base.CommonResult;
import com.file.manage.domain.data.UserInfo;
import com.file.manage.domain.request.UpdatePasswordRequest;
import com.file.manage.domain.service.UserService;
import com.file.manage.infrastructure.base.Pager;
import com.file.manage.infrastructure.base.dto.query.PageQuery;
import com.file.manage.infrastructure.dao.UserFileMappingDao;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @since 2025-05-22
 */
@RestController
@RequestMapping("user")
@Tag(name = "用户管理")
public class UserController {
    @Resource
    private UserService userService;


    @Operation(summary = "修改用户信息")
    @RequestMapping(value = "/updateUserInfo", method = RequestMethod.POST)
    public CommonResult<?> updateUserInfo(@Valid @RequestBody UpdateUserInfoRequest request) {
        userService.updateUserInfo(request);
        return CommonResult.success();
    }

    @Operation(summary = "获取当前用户信息")
    @RequestMapping(value = "/getCurrentUser", method = RequestMethod.GET)
    public CommonResult<UserInfo> getCurrentUser() {
        return CommonResult.success(userService.getCurrentUser());
    }

    @Operation(summary = "删除用户")
    @RequestMapping(value = "/deleteUser", method = RequestMethod.GET)
    public CommonResult<?> deleteUser(@RequestParam("id") String id) {
        userService.deleteUser(id);
        return CommonResult.success();
    }

    @Operation(summary = "查询用户")
    @RequestMapping(value = "/listUserInfo", method = RequestMethod.POST)
    public CommonResult<List<UserInfo>> listUserInfo(@RequestBody UserQueryParam param) {
        return CommonResult.success(userService.listUserInfo(param));
    }

    @Operation(summary = "分页查询用户")
    @RequestMapping(value = "/pageUserInfo", method = RequestMethod.POST)
    public CommonResult<Pager<UserInfo>> pageUserInfo(@RequestBody PageQuery<UserQueryParam> param) {
        return CommonResult.success(userService.pageUserInfo(param));
    }

}
